package com.lap.framework.base.entity;

import com.lap.framework.common.tool.JsonUtil;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;

/**
 *
 *
 * <pre>
 * 单元测试参数map
 * </pre>
 */
@Slf4j
public class ArgMap {

  private Map<String, Object> map = new HashMap<>();

  public ArgMap put(String key, Object value) {
    map.put(key, value);
    return this;
  }

  @SuppressWarnings("unchecked")
  public <T> T get(String key, Class<T> clazz) {
    log.info("class:{}", clazz.getName());
    return (T) map.get(key);
  }

  public String get(String key) {
    return get(key, String.class);
  }

  public Integer getInteger(String key) {
    return get(key, Integer.class);
  }

  public String getJson() {
    return JsonUtil.toJson(map == null ? empty() : map);
  }

  public static ArgMap empty() {
    ArgMap argMap = new ArgMap();
    argMap.map = Collections.emptyMap();
    return argMap;
  }
}
